<?php
/**
 * 资讯标签定义
 */
class TagLibArticle extends TagLib {
	protected $tags = array(
		'list' => array('attr' => 'field,where,order,limit,data', 'close' => 1)
	);
	
	public function _list($attr, $content) {
		$tag = $this->parseXmlAttr($attr, 'list');
		$field = isset($tag['field']) ? '->field(\''. $tag['field'] .'\')' : '->field(\'id,title,viewimage,description\')';
		$where = isset($tag['where']) ? '->where(\''. $tag['where'] .'\')' : '';
		$order = isset($tag['order']) ? '->order(\''. $tag['order'] .'\')' : '->order(\'id desc\')';
		$num = isset($tag['limit']) ? $tag['limit'] : 10;
		$data = isset($tag['data']) ? $tag['data'] : 'data';  // 数据存储
		
		$s = '<?php ';
		$s .= '$' . $data . '=M("Article")' . $field. $where . $order .'->limit(\''.$num.'\')->select();';
		$s .= 'if(is_array($'.$data.')){ ?>' . $content;
		$s .= '<?php } ?>';
		
		return $s;
	}
}

